package org.dromara.system.service.impl;

import com.baomidou.dynamic.datasource.annotation.DS;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import jakarta.annotation.Resource;
import org.apache.commons.collections4.CollectionUtils;
import org.dromara.common.core.utils.TimeUtil;
import org.dromara.system.domain.ZService;
import org.dromara.system.domain.vo.ZServiceChartVO;
import org.dromara.system.mapper.ZServiceMapper;
import org.dromara.system.service.IZServiceService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;
@DS("second")
@Service
public class ZServiceServiceImpl extends ServiceImpl<ZServiceMapper, ZService> implements IZServiceService {
    private static final Logger log = LoggerFactory.getLogger(ZServiceServiceImpl.class);
    @Resource
    private ZServiceMapper zServiceMapper;

    @Override
    public Map<String, Integer> getData(Integer timeCode, String startTime, String endTime) {
        log.info("[ZServiceServiceImpl][getData]enter, timeCode:{}, startTime:{}, endTime:{}", new Object[]{timeCode, startTime, endTime});
        String time = TimeUtil.buildTime(timeCode, startTime, endTime);
        List<ZServiceChartVO> zServiceList = this.zServiceMapper.getAppealChannels(time);
        Map<String, Integer> map = new HashMap();
        zServiceList.stream().forEach((z) -> {
            map.put(z.getChartName(), z.getChartNum());
        });
        log.info("[ZServiceServiceImpl][getData]result:{}, timeCode:{}, startTime:{}, endTime:{}", new Object[]{map.size(), timeCode, startTime, endTime});
        return map;
    }
    @Override
    public List<ZServiceChartVO> getHotProblem(String time) {
        log.info("[ZServiceServiceImpl][getHotProblem]enter, time:{}", time);
        List<ZServiceChartVO> result = this.zServiceMapper.getHotProblem(time);
        log.info("[ZServiceServiceImpl][getHotProblem]result:{}, time:{}", CollectionUtils.size(result), time);
        return result;
    }
    @Override
    public List<ZServiceChartVO> getLevelOneProblem(String time) {
        log.info("[ZServiceServiceImpl][getLevelOneProblem]enter, time:{}", time);
        List<ZServiceChartVO> result = zServiceMapper.getLevelOneProblem(time);
        log.info("[ZServiceServiceImpl][getLevelOneProblem]result:{}, time:{}", CollectionUtils.size(result), time);
        return result;
    }


}

